<template>
  <div class="password">
    <div class="mask"></div>
    <div class="checkoutMain">
      <div class="close">
        <p>密码验证</p>
        <i class="el-icon-close" @click="handleClosePassword"></i>
      </div>
      <div class="form-data">
        <div class="form-item">
          <span class="mr-8">密码</span>
          <el-input
            class="update-input"
            style="width: 240px"
            placeholder="请输入密码"
            type="password"
            v-model="requestData.pass"
          ></el-input>
        </div>
        <div class="btns">
          <el-button @click="handleClosePassword">取消</el-button>
          <el-button type="primary" @click="handleConfirmClick">确认</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { verifyPassword } from '@/request/store/K_storeSalesQuery'
export default {
  props: {
    vipPhone: {
      type: String,
      require: true,
      default: () => ''
    }
  },
  data() {
    return {
      requestData: {
        phone: '',
        pass: ''
      }
    }
  },
  created() {
    this.requestData.phone = this.vipPhone
  },
  methods: {
    // 确认
    async handleConfirmClick() {
      const mdRule = this.$md5(
        `${this.requestData.phone}:${this.requestData.pass}`
      )
      const params = {
        phone: this.vipPhone,
        pass: mdRule
      }
      const { data } = await verifyPassword(params)
      if (data && data.data && data.code === 200) {
        this.$emit('passwordCorrect', data.data)
      } else {
        this.$message.error('密码错误')
      }
    },
    handleClosePassword() {
      this.$emit('handleClosePassword')
    }
  }
}
</script>

<style lang="less" scoped>
.password {
  .mask {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0.3;
    z-index: 99;
  }

  .checkoutMain {
    position: fixed;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    width: 350px;
    // height: 200px/;
    z-index: 99;
    background-color: white;
    overflow: auto;
    padding-bottom: 1.5vh;
    .close {
      display: flex;
      justify-content: space-between;
      background: #f4f4f4;
      padding: 10px 15px;
    }
    .form-data {
      margin: 24px;
      // margin-top: 30px;
      .btns {
        display: flex;
        justify-content: flex-end;
        margin-top: 24px;
      }
    }
  }
}
</style>
